<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //get请求;
        fetch("http://127.0.0.1/get").then(response => {
            //返回的解析后的json数据会传递给下一个then方法中的回调函数作为参数,这个参数就是data;
            return response.json();
        }).then(data => {
            console.log("get.data:",data)
        }).catch(error=>{
            console.log("get.error:",error.message)
        }).finally(()=>{
            console.log("get.finally")
        })
        
        //post请求;
        let data = {
            name: '梁轩',
            web: 'liangxuancode.com',
        }
        axios.post('http://127.0.0.1/post',data,{
            Headers: { 
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }).then(response => {
            console.log("post.data:",response.data)
        }).catch(error =>{
            console.log("post.error:",error)
        }).finally(()=>{
            console.log("post.finally")
        })
    </script>
</body>
</html>